// pages/login/index.js
Page({
  data: {},
  //表单提交按钮
  submit: function (e) {
    console.log('form发生了submit事件，携带数据为：', e.detail.value)
    var _this = this;
    wx.showLoading({
      title: '加载中',
      mask: true
    })
    wx.request({
      url: 'http://43.139.97.111:8080/user/login?username=' +
        e.detail.value.username +
        '&password=' + e.detail.value.password,
      method: 'GET',
      header: {
        'content-type': 'application/json' // 默认值
      },
      success(res) {
        console.log(res.data.data);
        if (res.data.code == 200) {
          wx.setStorageSync('userInfo', res.data.data)
          wx.hideLoading()
          wx.switchTab({
            url: '/pages/user/user',
          })
          _this.setData({
            userinfo: res.data.data
          })
          wx.hideLoading()
        } else {
          wx.showModal({
            title: '提示',
            content: res.data.data,
            success(res) {
              if (res.confirm) {
                console.log('用户点击确定')
              } else if (res.cancel) {
                console.log('用户点击取消')
              }
            }
          })
          wx.hideLoading()
        }
      },
      fail: function (res) {

      },
    })
  },
  //表单重置按钮

  goToRegister: function (e) {
    wx.navigateTo({
      url: '/pages/register/register',
    })
    this.setData({

    })

  },
  handleGetUserInfo(e) {
    // console.log(e);

    const {
      userInfo
    } = e.detail;
    wx.setStorageSync("userinfo", userInfo);
    wx.switchTab({
      url: '/pages/user/user'
    });

  }
})